<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-15 10:20:57
 * @Last Modified time: 2023-02-15 12:20:33
 */

namespace app\console\task;

use frank\base\BaseTask;
use app\console\services\store\OrderService;

/**
 * 定时任务：商城订单
 * Class StoreOrderTask
 * @package app\console\task
 */
class StoreOrderTask extends BaseTask
{
    // 当前任务唯一标识
    private $taskKey = 'StoreOrderTask';

    // 任务执行间隔时长 (单位:秒)
    protected $taskExpire = 10 * 1;

    /**
     * 任务处理
     */
    public function handle()
    {
        $this->setInterval($this->taskKey, $this->taskExpire, function () {
            echo $this->taskKey . PHP_EOL;
            // 未支付订单自动关闭
            $count = $this->closeEvent();
            echo '未支付订单自动关闭:' .$count. PHP_EOL;
        });
    }

    /**
     * 未支付订单自动关闭
     */
    private function closeEvent()
    {
        // 执行自动关闭
        return OrderService::instance()->closeEvent((int)sysconf('store_order_close_time'));
    }
}